/**
 * this class is used to convert the SOAP format
 * to our customized alignment output format
 * mostly for debug
 * */

#include "gallop_common.h"

class Converter {
private:
	ifstream* _soapFile;
	unsigned int _readLength;
public:
	Converter() {};
	Converter(const char* soapFileName, const unsigned int _readLength);
	~Converter();


	/* clean the soap file for our testing
 	1. discard the reads with a different read length
	2. adjust the reads, make it strictly fit to the mismatch 
	 * */
	static void cleanSoap(string outFileName, string soapFileName, string refFileName, 
				const int readLength);

	/*convert the soap format to our binary format with range partitioning*/
	void run(const char* outFileName, 
		const unsigned int refLength, const unsigned int winSize, 
		const unsigned int bucketSize);

	/*filter alignments with a specific read length, discard alignments without the length*/
	void filterAlign(const char* outFileName);

private:
	void soap2bin(AlignResult* alignResult, const unsigned int qid, Soap_format* soap);
	static bool hasN(const char* buf, const int n) {
		bool is = false;
		for(int i = 0; i < n; i++) {
			if(buf[i] == 'N' || buf[i] == 'n') {
				is = true;
				break;
			}
		}
		return is;
	}

public:
	static void getMismatch(const char* str, unsigned char* offset, signed char* sub);
};

